/**
 * Copyright (c) 2013-5-6 上午11:50:35 WKM and/or its affiliates. 
 * Use is subject to license terms.
 * All rights reserved.
 */
package org.extblog.wkm.web.action.upload;

import javax.annotation.Resource;

import org.extblog.wkm.web.action.ActionController;
import org.extblog.wkm.web.service.upload.FileUploadService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author WKM
 * Service.java history
 * 1.WKM - 2013-5-6 - Create File
 */
@Controller
@RequestMapping("/upload")
public class FileUploadController extends ActionController {

	/** 文件上传服务管理 **/
	private FileUploadService fileUploadService = null;
	
	public FileUploadService getFileUploadService() {
		return fileUploadService;
	}

	@Resource
	public void setFileUploadService(FileUploadService fileUploadService) {
		this.fileUploadService = fileUploadService;
	}
	
	@RequestMapping(value="fileUpload.wkm",method=RequestMethod.POST)
	public ModelAndView upload(@RequestParam MultipartFile fileContent,Model model){
		ModelAndView mav = new ModelAndView();
		log.info("跳转到页面添加页面...");
		mav.setViewName("music/add");
		log.info("文件名称为:" + fileContent.getOriginalFilename());
		if(fileUploadService.addFile(fileContent)){
			mav.addObject("messageForm0", "操作成功！");
		} else {
			mav.addObject("messageForm0", "操作失败！");
		}
		return mav;
	}
	
	@RequestMapping("uploadPage.wkm")
	public ModelAndView gotoUpload(){
		ModelAndView mav = new ModelAndView();
		log.info("跳转到页面添加页面...");
		mav.setViewName("music/add");
		mav.addObject("messageForm0", "添加音乐");
		return mav;
	}
	
	
}
